<?php

namespace App\Http\Controllers\Api\V4;

use App\Common\ApiData;
use App\Models\V1\LearningOfficerMatter;
use App\Models\V1\LessonCenterNotice;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class NoticeController extends BaseController
{
    /**
     * @var ApiData
     */
    private $apiData;

    public function __construct(ApiData $apiData)
    {

        $this->apiData = $apiData;
    }

    /**
     * 获取所有的通知信息
     * @param LessonCenterNotice $lessonCenterNotice
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(LessonCenterNotice $lessonCenterNotice)
    {
        $noticeData = $lessonCenterNotice->get_all();

        return $this->apiData->set_data('notice_data', $noticeData)->send(200, '获取信息成功');
    }

    /**
     * @param $ID 通知的类型
     * @internal param 通知的ID $noticeID
     */
    public function show(Request $request, LearningOfficerMatter $learningOfficerMatter)
    {
        $ID = $request->ID;
        $noticeType = $request->noticeType;
        
        $id = DB::table('lesson_center_notice')->select('notice_id')
            ->where('id', $ID)
            ->where('type', $noticeType)
            ->pluck('notice_id')->toArray();

        if ($noticeType == 1) {//1为文章的消息的通知
            $data = $learningOfficerMatter->get_article_comment_data($id[0]);
            return $this->apiData->set_data('articel', $data)->send(200, '获取信息成功');
        } elseif ($noticeType == 0) {//为0为视频直播通知


        }
    }

    public function notice(Request $request)
    {
        Log::info($request->all());
//        dump($request->all());
    }
}























